package br.ufrgs.tst.ga.model;

import java.util.List;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import br.ufrgs.ga.fitness.TspTourFitnessCalculator;
import br.ufrgs.ga.model.GeneticModelFactory;
import br.ufrgs.ga.model.Individual;
import br.ufrgs.ga.model.Population;
import br.ufrgs.tsp.model.ICity;
import br.ufrgs.tst.TestHelper;

public class TestPopulation {

	private GeneticModelFactory geneticFactory = GeneticModelFactory.getInstance();
	private TspTourFitnessCalculator fitnessCalculator;
	
	Individual individual1;
	Individual individual2;
	Individual individual3;
	Individual individual4;
	
	private Population population;
	
	@Before
	public void setUp() {
		// Initial cities configuration for a TSP instance.
		List<ICity> citiesConfiguration = TestHelper.getCitiesConfigurationStub();
		fitnessCalculator = new TspTourFitnessCalculator(citiesConfiguration);
		
		individual1 = new Individual(geneticFactory.createChromosome("012340"), fitnessCalculator);
		individual2 = new Individual(geneticFactory.createChromosome("012341"), fitnessCalculator);
		individual3 = new Individual(geneticFactory.createChromosome("013340"), fitnessCalculator);
		individual4 = new Individual(geneticFactory.createChromosome("013440"), fitnessCalculator);
		
		this.population = new Population();
		this.population.add(individual1);
		this.population.add(individual4);
		this.population.add(individual2);
		this.population.add(individual3);
	}
	
	@Test
	public void getMostAdaptedIndividualTest() {
		Individual mostAdaptedIndividual = population.getMostAdaptedIndividual();
		Assert.assertEquals(individual1, mostAdaptedIndividual);
	}
}
